package nd.main;

import java.util.Date;
import java.util.Vector;

import presentation.*;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.ParseException;
import android.os.Bundle;
import android.widget.ListView;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;

public class MainActivity extends Activity {
	private Vector<RowData> data;
	RowData rd;
	
	static final String[] title = new String[] { "*New*Apple iPad Wi-Fi (16GB)", 
												 "7 Touch Tablet -2GB Google Android",
												 "Apple iPad Wi-Fi (16GB) Rarely Used ",
												 "Apple iPad Wi-Fi (16GB) AppleCase"};
	
	static final String[] detail = new String[] { "1h 37m Shipping: $10.00",
												  "1h 39m Shipping: Free",
												  "58m 6s Shipping: $10.00",
												  "59m 30s Shipping: $10.95"};
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
       
        loadList();
		loadTab();
    }
    
    public void loadList()
	{
    	data = new Vector<RowData>();
    	Date d = new java.util.Date();
    	
    	for( int i = 0; i < title.length; i++)
    	{
	    	try 
	    	{
	    	 	rd = new RowData(i, "", title[i], d);
	    	} 
	    	catch (ParseException e) 
	    	{
	    		e.printStackTrace();
	    	}
	    	data.add(rd);
    	}
    	HomeItemAdapter adapter = new HomeItemAdapter( this, 
    												   R.layout.item_home,
    												   R.id.itemtitle, 
    												   data);
    	
    	((ListView)findViewById(R.id.homelist)).setAdapter(adapter);
	}
	
	public void loadTab()
	{
		TabHost tabHost=(TabHost)findViewById(R.id.tabHost);
		
        tabHost.setup();

        TabSpec spec1=tabHost.newTabSpec("Home");
        spec1.setContent(R.id.homelist);
        spec1.setIndicator("",getResources().getDrawable(R.drawable.home));

        TabSpec spec2=tabHost.newTabSpec("Browse");
        spec2.setContent(R.id.homelist);
        spec2.setIndicator("",getResources().getDrawable(R.drawable.browse));

        TabSpec spec3=tabHost.newTabSpec("Search");
        spec3.setIndicator("",getResources().getDrawable(R.drawable.search));
        spec3.setContent(R.id.homelist);
        
        TabSpec spec4=tabHost.newTabSpec("Info");
        spec4.setIndicator("",getResources().getDrawable(R.drawable.info));
        spec4.setContent(R.id.homelist);

        tabHost.addTab(spec1);
        tabHost.addTab(spec2);
        tabHost.addTab(spec3);
        tabHost.addTab(spec4);
	}
}